#include <iostream>
#include <vector>
using namespace std;

int dfs(vector<int> &head, vector<int> &next, vector<int> &to, vector<int> &vis, int u, vector<int> &prev)
{

}

int main()
{
        int n, m;
        cin >> n >> m;
        vector<int> head(n + 1, 0);
        vector<int> next(m + 1, 0);
        vector<int> to(m + 1, 0);
        vector<int> vis(n + 1, 0);
        int cnt = 1;

        for(int i = 0; i < n; i++){
                int u, v;
                cin >> u >> v;
                next[cnt] = head[u];
                to[cnt] = v;
                head[u] = cnt++;
        }
}